<template>
    <div>
       <van-cell-group>
        <van-field v-model="value" placeholder="请输入商品名称" />
        </van-cell-group>
        <van-button type="primary" block class="add-button" @click="addition(value)">添加商品</van-button>
    </div>
</template>
<script>
import axios from 'axios'
export default {
  data () {
    return {
      value: ''
    }
  },
  created () {

  },
  methods: {
    addition (name) {
      var params = new URLSearchParams()
      params.append('name', name)
      axios({
        method: 'post',
        url: '/api/addproduct',
        data: params
      })
        .then(res => {
          console.log('res=>', res)
        })
        .catch(res => console.log(res))
      this.$router.push('/search')
    }
  }

}
</script>
<style lang="less" scoped>
.van-button{
    width: 95%;
    margin: 40px auto;
    background-color: #1989FA;
}
.van-cell-group{
    margin-top: 45px;
}
</style>
